package cn.csc.module.distribute.controller.app.downline;

import cn.csc.framework.common.pojo.CommonResult;
import cn.csc.framework.common.pojo.PageResult;
import cn.csc.module.distribute.controller.admin.downline.vo.DistributeDownlineRespVO;
import cn.csc.module.distribute.controller.app.downline.vo.AppDistributeDownlineReqVO;
import cn.csc.module.distribute.convert.downline.DistributeDownlineConvert;
import cn.csc.module.distribute.dal.dataobject.downline.DistributeDownlineDO;
import cn.csc.module.distribute.service.downline.DistributeDownlineService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import static cn.csc.framework.common.pojo.CommonResult.success;

/**
 * @author 云隐
 * @date 2025/4/23
 **/
@Api(tags = "APP用户 - 分销员团队")
@RestController
@RequestMapping("/distribute/downline")
@Validated
public class AppDistributeDownlineController {

    @Resource
    private DistributeDownlineService distributeDownlineService;

    @GetMapping("/team")
    @ApiOperation("我的团队列表信息")
    public CommonResult<PageResult<DistributeDownlineRespVO>> getDownlinePage(AppDistributeDownlineReqVO pageVO) {
        PageResult<DistributeDownlineDO> pageResult = distributeDownlineService.getAppDownlinePage(pageVO);
        return success(DistributeDownlineConvert.INSTANCE.convertPage(pageResult));
    }

    /**
     * 分销员关联下线
     * @param inviteCode 邀请码
     * @return
     */
    @PostMapping("relate")
    @ApiOperation("分销员关联下线")
    public CommonResult<Boolean> relate(@RequestParam("inviteCode") String inviteCode){
        distributeDownlineService.relate(inviteCode);
        return success();
    }


}
